﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace WindowsPhoneGameHungTrung
{
    public class GameOverScreen : AbstractScreen
    {
        private My2DSprite background;
        private My2DSprite btn_Play;

        SpriteFont font, font_highScore;
        MouseState ms;

        public GameOverScreen()
        {
            ms = new MouseState();
        }

        public override void LoadContent(ContentManager content)
        {
            font = content.Load<SpriteFont>(@"Font/GameOver");
            font_highScore = content.Load<SpriteFont>(@"Font/Score");

            Texture2D[] tmpTexture;
            Vector2 tmpVector;

            // ro
            tmpTexture = new Texture2D[1];
            tmpTexture[0] = content.Load<Texture2D>(Global.PATH_FILE_IMAGE + "border");

            tmpVector = new Vector2((Global.SCREEN_WIDTH - tmpTexture[0].Width)/2,
                (Global.SCREEN_HEIGHT - tmpTexture[0].Height)/2);

            background = new My2DSprite(tmpTexture, tmpVector);

            // button play 

            tmpTexture = new Texture2D[1];
            tmpTexture[0] = content.Load<Texture2D>(Global.PATH_FILE_IMAGE + "play");

            tmpVector = new Vector2( 
                background.Position.X + background.getWidthTexture() / 2 + 50,
                background.Position.Y + background.getHeightTexture()/2);

            btn_Play = new My2DSprite(tmpTexture, tmpVector); 
        }

        bool bPress = false;

        public override void Update(GameTime gameTime)
        {
            if (Global.GAME_STATE == Global.GAMESTATE_ENUM.GAME_OVER)
            {
                ms = Mouse.GetState();
                if (btn_Play.IsSelected(ms.X, ms.Y))
                {
                    btn_Play.UpdateColor(Color.Yellow);

                    if (ms.LeftButton == ButtonState.Pressed && bPress == false)
                    {
                        bPress = true;
                        Global.GAME_STATE = Global.GAMESTATE_ENUM.START;
                        Global.IS_START_GAME = true;
                    }
                    if (ms.LeftButton == ButtonState.Released)
                    {
                        if (bPress == true)
                            bPress = false;
                    }
                }
                else
                    btn_Play.UpdateColor(Color.White);

                background.Update(gameTime);
                btn_Play.Update(gameTime);
            }
        }

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            if (Global.GAME_STATE == Global.GAMESTATE_ENUM.GAME_OVER)
            {
                background.Draw(gameTime, spriteBatch);
                btn_Play.Draw(gameTime, spriteBatch);
                spriteBatch.DrawString(font, "GAME OVER",
                    new Vector2(background.Position.X + 75, background.Position.Y + 50),
                    Color.Red);

                spriteBatch.DrawString(font_highScore, "High Score: " + Global.HIGHSCORE.ToString(),
                    new Vector2(background.Position.X + 50,
                        background.Position.Y + background.getWidthTexture() / 3),
                    Color.Red);

                spriteBatch.DrawString(font_highScore, "Your Score: " + Global.SCORE.ToString(),
                    new Vector2(background.Position.X + 50,
                         background.Position.Y + background.getWidthTexture() / 2),
                     Color.Red);
            }
        }
    }
}
